package com.cy.lib.util;

import android.content.Context;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * Created by CY on 2015/8/29.
 */
public class PropertiesUtils {

    public static void storeAccount(Context context, String username, String password, String remember) throws IOException {

        File file = new File(context.getDir("file", Context.MODE_APPEND), "data");
        FileOutputStream fos = new FileOutputStream(file);
        Properties properties = new Properties();
        properties.put("username", username);
        properties.put("password", password);
        properties.put("remember", remember);
        properties.store(fos, "comment");
        fos.close();
    }

    public static String[] readAccount(Context context) throws IOException {
        File file = new File(context.getDir("file", Context.MODE_APPEND), "data");
        if (!file.exists()) {
            return null;
        }
        Properties properties = new Properties();
        FileInputStream fis = new FileInputStream(file);
        properties.load(fis);
        String username = properties.getProperty("username");
        String password = properties.getProperty("password");
        String remember = properties.getProperty("remember");

        return new String[]{username, password, remember};
    }

}
